package com.hejia.alauda.convert;

import java.util.ArrayList;
import java.util.List;

import static org.springframework.util.CollectionUtils.*;
import static java.util.Collections.*;

public class DataHandler {
	
	@SuppressWarnings("rawtypes")
	private List list;

	@SuppressWarnings("rawtypes")
	public DataHandler(List list) {
		super();
		this.list = list;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List convert(RowMapper rowMapper) {
		if(isEmpty(getList())){
			return EMPTY_LIST;
		}
		List afterConvertList = new ArrayList(getList().size());
		int rowNum = 0;
		for(Object rs:getList()){
			afterConvertList.add(rowMapper.mapRow(rs, rowNum++));
		}
		return afterConvertList;
	}

	@SuppressWarnings("rawtypes")
	public List getList() {
		return list;
	}

	@SuppressWarnings("rawtypes")
	public void setList(List list) {
		this.list = list;
	}
}
